<template>
  <div class="system-panel-wrapper log-wrapper">
    <search-form
      :search-fields="searchFields"
      :search-form="searchForm"
      :rules="logRule"
      @handle-search="handleSearch"
    />
    <datagrid
      :data-list="logList"
      :columns="columns"
      :total="total"
      :current-page="pageNo"
      :page-size="pageSize"
      :loading="loading"
      :single-page-hide="false"
      @handle-size-change="handleSizeChange"
      @handle-current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import SearchForm from '@/components/SearchForm'
import Datagrid from '@/components/Datagrid'
import { getAction } from '@/api/action';

export default {
  name: 'LogManage',
  components: { SearchForm, Datagrid },
  data() {
    return {
      url: '/api/sysLog/getConditionLog',
      loading: false,
      logList: [],
      total: 0,
      pageNo: 1,
      pageSize: 10,
      logRule: {
        title: [{ required: true, message: '此项不能为空', trigger: 'blur' }],
        content: [{ required: true, message: '此项不能为空', trigger: 'blur' }],
        author: [{ required: true, message: '此项不能为空', trigger: 'blur' }],
        notice_user: [{ required: true, message: '此项不能为空', trigger: 'blur' }]
      },
      searchFields: {
        startTime: '',
        endTime: '',
        // operMoudl: '',
        handlers: ''
      },
      searchForm: [{
        label: '开始时间',
        field: 'startTime',
        type: 'datetime'
      }, {
        label: '结束时间',
        field: 'endTime',
        type: 'datetime'
      }, {
        label: '操作者',
        field: 'handlers',
      },
        // {
        //   label: '操作模块',
        //   field: 'operMoudl',
        //   type: 'select',
        //   options: [{
        //     label: '日志管理',
        //     value: '日志管理'
        //   }]
        // }
      ],
      columns: [
        {
          label: '操作者',
          width: '',
          prop: 'handlers'
        }, {
          label: '描述',
          width: '',
          prop: 'operDesc'
        }, {
          label: 'IP',
          width: '',
          prop: 'operIp'
        }, {
          label: '操作时间',
          width: '',
          prop: 'operCreateTime'
        },
        {
          label: '操作模块',
          width: '',
          prop: 'operModul', // operType
        }
      ]
    }
  },
  created() { this.init(); },
  methods: {
    async init() {
      this.loading = true;
      // 操作者不是模糊查询
      const obj = {
        pageNo: this.pageNo, pageSize: this.pageSize
      };
      for (const key in this.searchFields) {
        if (Object.hasOwnProperty.call(this.searchFields, key)) {
          const val = this.searchFields[key];
          if (val) {
            obj[key] = val;
          }
        }
      }
      await getAction(this.url, obj).then(res => {
        console.log('日志管理', res);
        this.logList = [];
        this.total = 0;
        if (res.msg === "成功" && res.objects) {
          this.logList = res.objects;
          this.total = res.total;
        }
      });
      this.loading = false;
    },
    handleSearch() {
      this.init();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.pageNo = val;
      this.init();
    }
  }
}
</script>

<style lang="scss"></style>
